package jeye.client.util;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;

public class LineReader extends InputStreamReader {
	
	private InputStream inputStream;

	public LineReader(InputStream inputStream, String encoding) throws UnsupportedEncodingException {
		super(inputStream, encoding);
		this.inputStream = inputStream;
	}

	public LineReader(InputStream inputStream) {
		super(inputStream);
		this.inputStream = inputStream;
	}
	
	public String readLine() throws IOException {
		StringBuffer sb = new StringBuffer();
		int b = read();
		char chr = (char)b;
		
		while((b > -1) && (chr != '\n')) {
			if(chr != '\r') {
				sb.append(chr);
			}
			
			b = read();
			chr = (char)b;
		}
		return (sb.length() == 0) ? null : sb.toString(); 
	}

	public int read() throws IOException {
		return inputStream.read();
	}

}
